
/*
 * Copyright 2021 The Modelbox Project Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "modelbox/base/device.h"

#include <memory>

#include "com_modelbox_Device.h"
#include "jni_native_object.h"
#include "throw.h"
#include "utils.h"

/*
 * Class:     com_modelbox_Device
 * Method:    DeviceGetType
 * Signature: ()Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL
Java_com_modelbox_Device_DeviceGetType(JNIEnv *env, jobject j_this) {
  auto n_device =
      modelbox::JNINativeObject::GetNativeSharedPtr<modelbox::Device>(env,
                                                                      j_this);
  if (n_device == nullptr) {
    modelbox::ModelBoxJNIThrow(env, modelbox::StatusError);
    return nullptr;
  }

  return env->NewStringUTF(n_device->GetType().c_str());
}

/*
 * Class:     com_modelbox_Device
 * Method:    DeviceGetDeviceID
 * Signature: ()Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL
Java_com_modelbox_Device_DeviceGetDeviceID(JNIEnv *env, jobject j_this) {
  auto n_device =
      modelbox::JNINativeObject::GetNativeSharedPtr<modelbox::Device>(env,
                                                                      j_this);
  if (n_device == nullptr) {
    modelbox::ModelBoxJNIThrow(env, modelbox::StatusError);
    return nullptr;
  }

  return env->NewStringUTF(n_device->GetDeviceID().c_str());
}
